package com.jiyun.service;

import com.jiyun.mapper.FaDanMapper;
import com.jiyun.mapper.MessagePondMapper;
import com.jiyun.mapper.UserMapper;
import com.jiyun.pojo.entity.Order;
import com.jiyun.pojo.entity.User;
import com.jiyun.pojo.vo.OrderVo;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class QiDanService {
    @Autowired(required = false)
    private FaDanMapper faDanMapper;
    @Autowired(required = false)
    private UserMapper userMapper;
    @Autowired(required = false)
    private MessagePondMapper messagePondMapper;


    public User QiDan(Integer ptid, Integer oid) {
        Order order = faDanMapper.selectOrderByid(oid);
        order.setPtid(ptid);
        order.setStatusid(5);
        order.setOrdertime(new Date());
        faDanMapper.updateByPrimaryKeySelective(order);
        messagePondMapper.deleteByPrimaryKey(oid);
        Integer userid = order.getUserid();
        User user = userMapper.selectByPrimaryKey(userid);
        return user;
    }
    public void songda(Integer oid) {
        Order order = faDanMapper.selectByPrimaryKey(oid);
        order.setStatusid(6);
        faDanMapper.updateByPrimaryKeySelective(order);
    }
    public List<OrderVo> findPaotuiorder(Integer ptid) {
        return  faDanMapper.findPaotuiorder(ptid);
    }
    public List<OrderVo> selectstatus(Integer ptid, Integer seid) {
        if (seid==0){
            return faDanMapper.findPaotuiorder(ptid);
        }
        return faDanMapper.selectstatus(ptid,seid);
    }


    public void queren(Integer oid) {
        Order order = new Order();
        order.setOid(oid);
        order.setStatusid(6);
        faDanMapper.updateByPrimaryKeySelective(order);
    }
}
